package com.vic.mvc.framework.util;

public class StringUtil {
	public static boolean isNotEmpty(String str) {
		if(str != null && !"".equals(str)){
			return true;
		}
		return false;
	}
	
	public static boolean isEmpty(String str) {
		return str==null||"".equals(str);
	}
	
	
	public static String replaceAll(String str,String regex, String replacement) {
		return str.replaceAll(regex, replacement);
	}
	
	/**
	 * 驼峰式  转下划线
	 */
	public static String toUnderLine(String str){
		if(isNotEmpty(str)){
			return str.replaceFirst(str.substring(0,1), str.substring(0,1).toLowerCase())
					.replaceAll("[A-Z]", (UNDERLINE + "$0")).toLowerCase();
		}
		return null;
	}
	
	/**
	 *  大小写互转
	 */
	public static String reverseUpLow(String str){
		if(isNotEmpty(str)){
			return  str.replaceAll("([A-Z])", "$1XXX");
		}
		
		return null;
		
	} 
	/**
	 * 下划线转驼峰式
	 */
	public static String toHump(String str){
		if(isNotEmpty(str)){
			String[] strArr = str.split(UNDERLINE);
			StringBuilder sb = new StringBuilder("");
			for(String s : strArr) {
				sb.append(s.replaceFirst(s.substring(0,1), s.substring(0,1).toUpperCase()));
			}
			return sb.toString();
		}
		return "";
	}
	
	private static final String UNDERLINE = "_";
	
	
	public static void main(String[] args) {
		String a = "TestTable";
		String b = toUnderLine(a);
		String c = toHump(b);
		System.out.println(b);
		System.out.println(c);
		
		String d = "AbcdEf";
		System.out.println(reverseUpLow(d));
	}
}
